<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin = new admin();
$admin->canView($_SERVER['PHP_SELF']);
ob_start("sanitize_output"); 

?>
<h2 class="form-heading">Add a new page</h2>
<form class="inline" action="/admin/resources/php/requests/actions/add-page.php">
<input type="hidden" class="settings" value='{"buttonWaitingValue":"Adding","updateNode":"#response"}' />	
	<table width="100%" cellpadding="2" cellspacing="2">
    	<tr valign="top">
        	<td width="28%"><strong>Page Name:</strong></td>
            <td width="72%"><input type="text" class="form-field req" name="add_page_name" id="add_page_name" style="width:250px;" /> <span class="hint">(name to appear in the site menu)</span></td>
        </tr>
        <tr valign="top">
        	<td><strong>Page URL/Path:</strong></td>
            <td><input type="text" class="form-field req" name="add_page_url" id="add_page_url" style="width:250px;" /> <span class="hint">(with leading / trailing slashes)</span></td></tr>
            <tr valign="top">
        	<td><strong>Page H1 heading:</strong></td>
            <td><input type="text" class="form-field" name="add_page_heading" id="add_page_heading" style="width:250px;" /> <span class="hint">(recommended)</span></td>
            </tr>
            <tr valign="top">
        	<td><strong>Menu Order:</strong></td>
            <td><input type="text" class="form-field req" name="add_page_order" id="add_page_order" style="width:30px;" /> <span class="hint">(order in the menu [low to high])</span></td></tr>
            <tr valign="top">
        	<td><strong>Parent:</strong></td>
            <td><select class="form-field" name="add_page_parent" id="add_page_parent" style="width:250px;"><?php echo(get_parent_pages_as_opts()); ?></select> <span class="hint">Is the page part of the sub menu navigation </span></td></tr>
            <tr valign="top">
        	<td><strong>Include Sidebar:</strong></td>
            <td><select class="form-field" name="add_page_sidebar" id="add_page_sidebar" style="width:56px;"><?php echo($admin->selectYesNo(0)); ?></select> <span class="hint">Include the sidebar?</span></td>
        </tr>
        <tr valign="top">
        	<td><strong>Is Blog Page:</strong></td>
            <td><select class="form-field" name="add_page_is_blog" id="add_page_is_blog" style="width:56px;"><?php echo($admin->selectYesNo(0)); ?></select> <span class="hint">Is the page the sites blog?</span></td>
        </tr>
         <tr valign="top">
        	<td><strong>Include In Nav:</strong></td>
            <td><select class="form-field" name="add_page_include_in_nav" id="add_page_include_in_nav" style="width:56px;"><?php echo($admin->selectYesNo(1)); ?></select> <span class="hint">Show in site navigation?</span></td>
        </tr>
        <tr valign="top">
        	<td><strong>Require Logged In User:</strong></td>
            <td><select class="form-field" name="add_page_requires_auth" id="add_page_requires_auth" style="width:56px;"><?php echo($admin->selectYesNo(0)); ?></select> <span class="hint">(relies on user componant)</span></td>
        </tr>
        <tr valign="top">
        	<td><strong>Require Group(s)<br />(read access):</strong></td>
            <td>
            	<div class="form-field" style="height:100px;overflow-y:hidden;overflow-x:auto;width:250px;">
                <ul>
				<?php
					$groups=$admin->getGroups();
					foreach($groups as $row) {
						echo('<li><input type="checkbox" name="add_page_group[]" value="'.$row['id'].'" /> <strong>'.$row['label'].'</strong></li>');	
					}
				
				?>	
                </ul>
                </div>
                <p class="hint">No groups selected means all users can view.</p>
            </td>
        </tr>
    </table>
    <p>Once the page has been added you will be able to edit it including adding a contact form to it.</p>
    <input type="submit" class="button" value="Add page" />

</form>